﻿using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ZFCNew.Code
{
    public class IsolatedStorageHelper
    {
        private static readonly IsolatedStorageSettings _appSettings = IsolatedStorageSettings.ApplicationSettings;
        private const string IsExistingUser = "IsExistingUser";

        public static  bool IsFirstTime()
        {
            bool isExisting = false;
            _appSettings.TryGetValue(IsExistingUser, out isExisting);
            return !isExisting;
        }

        public static void SetExistingUser()
        {
            _appSettings.Add(IsExistingUser, true);
        }

        private void SaveData(string data, string fileName)
        {

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {

                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
                {

                    using (StreamWriter sw = new StreamWriter(isfs))
                    {

                        sw.Write(data);

                        sw.Close();

                    }

                }

            }

        }
        private string LoadData(string fileName)
        {

            string data = String.Empty;

            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {

                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Open, isf))
                {

                    using (StreamReader sr = new StreamReader(isfs))
                    {

                        string lineOfData = String.Empty;

                        while ((lineOfData = sr.ReadLine()) != null)

                            data += lineOfData;

                    }

                }

            }

            return data;

        }
    }
}
